package btd.game.dlgs;

import btd.game.activities.PBoardAct;
import btd.game.activities.R;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.TextView;

public class ColorDlg extends Dialog {
	private String bName = "";
	private String wName = "";
	private PBoardAct owner = null;
	public ColorDlg(Context context, String bName, String wName) {
		super(context);
		owner = (PBoardAct) context;
		this.bName = bName;
		this.wName = wName;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.colorinfo);
		((TextView) findViewById(R.id.TextViewCIBName)).setText(bName);
		((TextView) findViewById(R.id.TextViewCIWName)).setText(wName);
		owner.closeRandomView();
		new Thread(closeRun).start();
	}
	
	private Runnable closeRun = new Runnable() {
		public void run() {
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				//e.printStackTrace();
			}
			if(owner.isBF) {
				owner.lStartSubTime();
			} else {
				owner.dStartSubTime();
			}
			ColorDlg.this.cancel();
		}
	};

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		super.onKeyDown(keyCode, event);
		if(keyCode == KeyEvent.KEYCODE_BACK) {
			return true;
		}
		//if(owner.isBF) {
		//	owner.lStartSubTime();
		//} else {
		//	owner.dStartSubTime();
		//}
		//this.cancel();
		return false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		super.onTouchEvent(event);
		//if(event.getAction() == MotionEvent.ACTION_DOWN) {
		//	if(owner.isBF) {
		//		owner.lStartSubTime();
		//	} else {
		//		owner.dStartSubTime();
		//	}
		//	this.cancel();
		//}
		return true;
	}
}
